<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>热力图</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
    <style>
        html,
        body,
        #container {
            margin: 0;
            padding: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript" src="../js/layui/layui.all.js"></script>
<script src="https://webapi.amap.com/maps?v=1.4.15&key=cbe5ed218789ffe1858ed5d6432204a9"></script>
<script>
    const map = new AMap.Map("container", {
        resizeEnable: true,
        center: [104.066143, 30.573095],
        zoom: 12,
        mapStyle: "amap://styles/grey"
    });

    if (!isSupportCanvas()) {
        alert('热力图仅对支持canvas的浏览器适用,您所使用的浏览器不能使用热力图功能,请换个浏览器试试~')
    }

    let heatmap;
    const $ = layui.$;
    $.post({
        url: "http://127.0.0.1/foodShopSearch/queryHeatMap",
        success: function (res) {
            console.log(res);
            map.plugin(["AMap.Heatmap"], function () {
                //初始化heatmap对象
                heatmap = new AMap.Heatmap(map, {
                    radius: 25, //给定半径
                    opacity: [0, 0.8]
                });
                //设置数据集
                heatmap.setDataSet({
                    data: res,
                    max: 100
                });
            });
        }
    });

    //判断浏览区是否支持canvas
    function isSupportCanvas() {
        var elem = document.createElement('canvas');
        return !!(elem.getContext && elem.getContext('2d'));
    }
</script>
</body>
</html>